<template>
  <span>
        {{ nowtime }}
  </span>
</template>

<script>
export default {
  name: 'Timecard',
  data () {
    return {
      msg: '2333',
      nowtime: '死命加载中啦（实际上要等1s）'
    }
  },
  methods: {
    getTime: function () {
      let DateObject = new Date()
      let Year = DateObject.getFullYear()
      let Month = DateObject.getMonth() + 1
      let Day = DateObject.getDate()
      let Hour = DateObject.getHours()
      let Minute = DateObject.getMinutes()
      let Second = DateObject.getSeconds()
      return Year + '-' + Month + '-' + Day + ' ' + (Hour>=10?Hour:('0'+Hour)) + ':' + (Minute>=10?Minute:('0'+Minute)) + ':' + (Second>=10?Second:('0'+Second))
    },
  },
  mounted () {
    let _this = this
    this.timer = setInterval(() => {
      _this.nowtime = _this.getTime()
    }, 500)
  },
  beforeDestroy () {
    if (this.timer) {
      clearInterval(this.timer)
    }
  }
}
</script>
